package com.szholly.pro.watergas_server.water.operationsunit;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.ITable;
import com.szholly.data.general.ITableFactory;
import com.szholly.data.general.RowBase;
import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.utils.spring.SpringBeanFactory;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Service;

@Aspect
@Service
public class OperationsUnitService {
	public List<RowBase> getList(Map<String, String> params)
			throws Exception {
		String sql ="select t.* from OPERATIONS_UNIT t left join BC_ENTERPRISE_ATTR t1 on t1.OPERATOR=t.guid  where 1=1 ";

		List<GlobalParameter> listParam = new ArrayList<>();
		if (params.containsKey("GUID")) {
			sql += " and t.GUID=@GUID";
			listParam.add(new GlobalParameter("GUID", params.get("GUID")));
		}
		if (params.containsKey("WWTP_ID")) {
			sql += " and t1.exp_no=@WWTP_ID";
			listParam.add(new GlobalParameter("WWTP_ID", params.get("WWTP_ID")));
		}
		ITableFactory tableFactory = (ITableFactory) SpringBeanFactory.getBean("TableFactory");
		ITable pTable = tableFactory.openTable("OPERATIONS_UNIT");
		return DataUtil.getSelectRows(sql, listParam, pTable);
	}
}
